package com.example.pixelyear.utils

import android.annotation.SuppressLint
import android.content.Context
import com.example.pixelyear.MyApp

/**
 * Sp工具类
 * Created by Administrator on 2018/5/3.
 */
object YxsSpUtils {
    private const val tag = "-1"
    private const val empty = ""

    private val Sp by lazy {
        MyApp.getContext().getSharedPreferences("yxsSp", Context.MODE_PRIVATE)
    }
    private val Edit by lazy {
        Sp.edit()
    }

    fun putBoolean(name: String, msg: Boolean): Boolean = Edit.putBoolean(name, msg).commit()

    fun getBoolean(name: String, default: Boolean = false): Boolean = Sp.getBoolean(name, default)

    fun putString(name: String, msg: String): Boolean = Edit.putString(name, msg).commit()

    fun getString(name: String, default: String = empty): String = Sp.getString(name, default)!!

    fun putInt(name: String, msg: Int): Boolean = Edit.putInt(name, msg).commit()

    fun getInt(name: String, default: Int = tag.toInt()): Int = Sp.getInt(name, default)

    fun putFloat(name: String, msg: Float): Boolean = Edit.putFloat(name, msg).commit()

    fun getFloat(name: String, default: Float = 0f): Float = Sp.getFloat(name, default)

    fun putLong(name: String, msg: Long): Boolean = Edit.putLong(name, msg).commit()

    fun getLong(name: String, default: Long = tag.toLong()): Long = Sp.getLong(name, default)

    fun remove(name: String) = Edit.remove(name).commit()
}